#include"lottery_sys.h"
L_buyed_t* load_buyed_lott(void)
{
	FILE* fpi = NULL;
	L_buyed_t* buyed_head = NULL;
	L_buyed_t* tail = NULL;
	L_buyed_t* cur = NULL;
	int ret = 0;
	buyed_head = init_buyed_lott();
	tail = buyed_head;
	cur = (L_buyed_t*)calloc(1,sizeof(L_buyed_t));
	if(!cur)
	{
		return NULL;
	}
	fpi = fopen(HIS_LOTTERY_FILE,"rb");
	if(!fpi)
	{
		printf("彩票文件加载失败！\n");
		free(cur);
		return buyed_head;
	}
	while(1)
	{
		ret = fread(cur,sizeof(L_buyed_t),1,fpi);
		if(ret < 1)
		{
			break;
		}
		//文件读取,尾插法加载用户链表
		tail -> next = cur;            
		tail = cur;
		cur = (L_buyed_t*)calloc(1,sizeof(L_buyed_t));
		if(!cur)
		{
			return NULL;
		}
	}
	tail -> next = NULL;
	free(cur);
	fclose(fpi);
	//  show_lott_list(buyed_head);
	return buyed_head;
}

